#include "video_frame.h"

// 计算采集到编码的延迟（毫秒）
double VideoFrame::getCaptureToEncodeLatency() const {
    if (encode_time_ <= capture_time_) return 0.0;
    auto duration = std::chrono::duration_cast<std::chrono::microseconds>(encode_time_ - capture_time_);
    return duration.count() / 1000.0;
}

// 计算编码到发送的延迟（毫秒）
double VideoFrame::getEncodeToSendLatency() const {
    if (send_time_ <= encode_time_) return 0.0;
    auto duration = std::chrono::duration_cast<std::chrono::microseconds>(send_time_ - encode_time_);
    return duration.count() / 1000.0;
}

// 计算发送到接收的延迟（毫秒）
double VideoFrame::getSendToReceiveLatency() const {
    if (receive_time_ <= send_time_) return 0.0;
    auto duration = std::chrono::duration_cast<std::chrono::microseconds>(receive_time_ - send_time_);
    return duration.count() / 1000.0;
}

// 计算接收到解码的延迟（毫秒）
double VideoFrame::getReceiveToDecodeLatency() const {
    if (decode_time_ <= receive_time_) return 0.0;
    auto duration = std::chrono::duration_cast<std::chrono::microseconds>(decode_time_ - receive_time_);
    return duration.count() / 1000.0;
}

// 计算解码到渲染的延迟（毫秒）
double VideoFrame::getDecodeToRenderLatency() const {
    if (render_time_ <= decode_time_) return 0.0;
    auto duration = std::chrono::duration_cast<std::chrono::microseconds>(render_time_ - decode_time_);
    return duration.count() / 1000.0;
}

// 计算端到端延迟（毫秒）
double VideoFrame::getEndToEndLatency() const {
    if (render_time_ <= capture_time_) return 0.0;
    auto duration = std::chrono::duration_cast<std::chrono::microseconds>(render_time_ - capture_time_);
    return duration.count() / 1000.0;
}
